

#: continued from 11/12, to be used in `11-try-run.zsh`. for now we just archive everything we have into ../log-db
# notes = '[Test] Hi password blacklist 123'
import sys
if len(sys.argv) > 1:
    notes = sys.argv[1]
else:
    raise ValueError("Please provide notes as a command line argument.")

from pathlib import Path
p0 = Path.cwd().parent / 'log'
p = next(p0.glob('*.pytestlog.json'))

# 0. translate the log file
from u import decode_base64_strings
o = json.loads(p.read_text(encoding='utf-8'))
o_decoded = decode_base64_strings(o)
p1 = p.with_suffix('.decoded.json')
p1.write_text(json.dumps(o_decoded, indent=2, ensure_ascii=False), encoding='utf-8')

class S:
    BLUE = '\033[94m'
    CYAN = '\033[96m'
    GREEN = '\033[92m'
    NOR = '\033[0m'

# 1. move the files
n = p.name.removesuffix('.pytestlog.json')  # get the name without the suffix
p1 = Path('../log-db') / n
p1.mkdir(parents=True, exist_ok=True)  # ensure the parent directory exists

# 1.1 mv log/* log-db/<n>
for f in p0.glob('*'):
    print(f"⚙️ Moving {S.BLUE}{f.name}{S.NOR} to {S.CYAN}{p1 / f.name}{S.NOR}")
    f.rename(p1 / f.name)
# 1.2 mv the test_o.py file there
Path('test_o.py').rename(p1 / 'test_o.py')
# 1.3 cp 11-try-render.yml to p1 / X.yml
from shutil import copyfile
copyfile('11-try-render.yml', p1 / 'X.yml')


# 2. update the log-db.json index file
# n = 'test_o_2025-06-30_18-34-40_98932'
# p1 = Path('../log-db') / n
# notes = '[Test] clear password-blacklist'
import json
j = Path.cwd().parent / 'log-db' / 'log-db.json'
idx = json.loads(j.read_text(encoding='utf-8')) if j.exists() else {}
idx[n] = {
    'path': str(p1),
    'notes': notes,
}
j.write_text(json.dumps(idx, indent=4, ensure_ascii=False), encoding='utf-8')

